package logic.studentQuery_logic;

import java.util.Date;
import java.util.List;

import datasv.datafactorysv.StudentQueryDatasvFactory;
import datasv.studentQuery_datasv.StudentQueryDatasv;
import po.StudentPO;
import resultmessage.StudentQueryRM;
import vo.StudentVO;

public class CollegeStudentList {
	private StudentQueryDatasv studentQD;
	private List<String> studentList;
 CollegeStudentList(String collegeID) {
		super();
		StudentQueryDatasvFactory studentQDF = new StudentQueryDatasvFactory();
		studentQD = studentQDF.create();
		studentList = studentQD.getCollegeStudents(collegeID);
		// TODO Auto-generated constructor stub
	}
	 public List<String> getStudentList() {
	return studentList;
}
	private boolean containsStudent(String studentID){
		 for(String id : studentList){
			 if(id.equals(studentID)){
				 return true;
			 }
		 }
		 return false;
	 }
	public StudentQueryRM addStudent(StudentPO student){
		if(containsStudent(student.getCollegeID())){
			return StudentQueryRM.STUDENT_EXIST;
		}
			studentQD.addStudent(student);
			return StudentQueryRM.SUCCESS;
	 }
	 public StudentQueryRM updateStudent(StudentPO student){
		 if(!containsStudent(student.getStudentID())){
			 return StudentQueryRM.STUDENT_NOT_EXIST;
		 }
		  studentQD.updateStudent(student);
		  return StudentQueryRM.SUCCESS;
	 }
	 public StudentQueryRM deleteStudent(String studentID){
		 if(!containsStudent(studentID)){
			 return StudentQueryRM.STUDENT_NOT_EXIST;
		 }
		 studentQD.deleteStudent(studentID);
		 return StudentQueryRM.SUCCESS;
	 }
}
